package com.jame.basics.thread.Issue;

import java.util.concurrent.TimeUnit;

/**
 * @author : Jame
 * @date : 2021-01-11 12:00
 **/
public class Test3 {

    public static void main(String[] args) throws InterruptedException {
        Phone3 phone3 = new Phone3();
        new Thread(Phone3::sendMessage).start();
        new Thread(Phone3::video).start();
        new Thread(phone3::call).start();
        /**
         * 如果static方法加上synchronized关键字锁的就是一个Class对象
         * 而打电话没有static锁的是对象,因为只有打电话方法是非静态并且加上锁
         * 那么打电话方法肯定可以拿到对象锁,而发短信拿到Class对象的锁后看视频就需要等待释放锁
         */
    }

}

class Phone3 {
    public static synchronized void sendMessage() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }

    public static   synchronized void video() {
        System.out.println("看视频");
    }
    public   synchronized void call() {
        System.out.println("打电话");
    }
}
